#include <nice2d/sprite.h>
#include <nice2d/components/spritestatus.h>

IMPLEMENT_OBJECT(SpriteStatus, Component)

class SpriteStatusData
{
public:
    int status = SPRITE_STATUS_NORMAL;
};

SpriteStatus::SpriteStatus():
    data(new SpriteStatusData())
{
}

SpriteStatus::~SpriteStatus()
{
}

void SpriteStatus::setSpriteStatus(int status)
{
    if (status == data->status) {
        data->status = status;
        if (getOwner().expired()) {
            statusChanged(nullptr, status);
        } else {
            auto sprite = std::dynamic_pointer_cast<Sprite>(getOwner().lock());
            statusChanged(sprite, status);
        }
    }
}

int SpriteStatus::getSpriteStatus() const
{
    return data->status;
}
